package com.css.fxfzdpzs.modules.ypg.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzdpzs.base.response.RestResponse;
import com.css.fxfzdpzs.modules.ypg.entity.first.*;
import com.css.fxfzdpzs.modules.ypg.entity.second.*;
import com.css.fxfzdpzs.modules.ypg.service.YpgService;
import com.css.fxfzdpzs.modules.ypg.vo.*;
import com.css.fxfzdpzs.util.PlatformObjectUtils;
import com.css.fxfzdpzs.util.PlatformPageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author y1fan
 * @description   ypg 大屏获取接口
 */
@RestController
@RequestMapping("/ypg")
@Slf4j
public class YpgController {


    @Resource
    private YpgService ypgService;


    /**
     * 预评估首页 （一级目录）4.1.36全国设定地震个数
     *
     * @return
     */
    @GetMapping("/getYpgEarthquakeSetNum")
    public RestResponse getYpgEarthquakeSetNum() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            YpgEarthquakeSetNum ypgEarthquakeSetNum = ypgService.getYpgEarthquakeSetNum();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(ypgEarthquakeSetNum);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }
    /**
     * 预评估首页 （一级目录）各省（直辖市）设定地震个数统计
     *
     * @return
     */
    @GetMapping("/getYpgProvinceEarthquakeSet")
    public RestResponse getYpgProvinceEarthquakeSet() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            List<YpgProvinceEarthquakeSet> ypgProvinceEarthquakeSets = ypgService.getYpgProvinceEarthquakeSet();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(ypgProvinceEarthquakeSets);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 预评估首页 （一级目录）自2015年以来破坏性地震验证情况统计
     *
     * @return
     */
    @GetMapping("/getYpg2015yearsEarthquakeSituation")
    public RestResponse getYpg2015yearsEarthquakeSituation() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            Ypg2015yearsEarthquakeSituation ypg2015yearsEarthquakeSituation = ypgService.getYpg2015yearsEarthquakeSituation();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(ypg2015yearsEarthquakeSituation);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }




    /**
     * 预评估首页 （一级目录）4.1.35设定地震个数增长趋势图
     *
     * @return
     */
    @GetMapping("/getYpgEarthquakeSetTrend")
    public RestResponse getYpgEarthquakeSetTrend() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            List<YpgEarthquakeSetTrend> ypgEarthquakeSetTrends = ypgService.getYpgEarthquakeSetTrend();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(ypgEarthquakeSetTrends);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 预评估首页 （一级目录）现场抽样复核情况
     *
     * @return
     */
    @GetMapping("/getYpgSceneCheckSituation")
    public RestResponse getYpgSceneCheckSituation(HttpServletRequest request) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            YpgSceneCheckSituationVO vo = ypgService.getYpgSceneCheckSituation(curPage,pageSize);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(vo);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }




    /**
     * 预评估首页 （一级目录）各省覆盖率
     *
     * @return
     */
    @GetMapping("/getYpgProvinceCoverageVO")
    public RestResponse getYpgProvinceCoverageVO(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            if (PlatformObjectUtils.isEmpty(code)){
                code="0";
            }
            List<YpgProvinceCoverage> ypgProvinceCoverages = ypgService.getYpgProvinceCoverageVO(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(ypgProvinceCoverages);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 预评估首页 （一级目录）县覆盖率
     *
     * @return
     */
    @GetMapping("/getcountyCoverage")
    public RestResponse getcountyCoverage(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        if (PlatformObjectUtils.isEmpty(code)){
            code="0";
        }
        try {
            BigDecimal countyCoverage= ypgService.getcountyCoverage(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(countyCoverage);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }
    /**
     * 预评估首页  地图
     *
     * @return
     */
    @GetMapping("/getMap")
    public RestResponse getMap(YpgFirstMapVO ypgFirstMapVO) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            List<YpgFirstResultVO> ypgFirstResultVOS = ypgService.getMap(ypgFirstMapVO);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(ypgFirstResultVOS);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 预评估      图层服务需要数据 gemo
     *
     * @return
     */
    @GetMapping("/getGemo")
    public RestResponse getGemo() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            ypgService.getGemo();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    //ypg_pro_survey_point_count


    /**
     * 预评估二级页面  ypg_pro_survey_point_count   各省（直辖市）抽样调查点数量统计
     *
     * @return
     */
    @GetMapping("/getSurveyPointCount")
    public RestResponse getSurveyPointCount(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            if (PlatformObjectUtils.isEmpty(code)){
                code="0";
            }
            List<YpgProSurveyPointCount> list = ypgService.getSurveyPointCount(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    /**
     * 预评估二级页面  乡镇覆盖率
     *
     * @return
     */
    @GetMapping("/getVillageCoverage")
    public RestResponse getVillageCoverage(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            if (PlatformObjectUtils.isEmpty(code)){
                code="0";
            }
            BigDecimal countyCoverage= ypgService.getVillageCoverage(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(countyCoverage);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 预评估二级页面    乡镇行政区 各省覆盖率
     *
     * @return
     */
    @GetMapping("/getProvinceVillageCov")
    public RestResponse getProvinceVillageCov(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            if (PlatformObjectUtils.isEmpty(code)){
                code="0";
            }
            List<YpgProvinceCoverage> ypgProvinceCoverages = ypgService.getProvinceVillageCov(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(ypgProvinceCoverages);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }



    /**
     * 预评估二级页面 ypg_survey_point_locality   抽样调查点所在地区统计
     *
     * @return
     */
    @GetMapping("/getSurveyPointLocality")
    public RestResponse getSurveyPointLocality(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            if (PlatformObjectUtils.isEmpty(code)){
                code="0";
            }
            YpgSurveyPointLocality entity = ypgService.getSurveyPointLocality(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(entity);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }



    /**
     * 预评估二级页面 抽样调查点采集情况（全国） //ypg_survey_point_situation
     *
     * @return
     */
    @GetMapping("/getSurveyPointSituation")
    public RestResponse getSurveyPointSituation(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            if (PlatformObjectUtils.isEmpty(code)){
                code="0";
            }
            List<YpgSurveyPointSituation> list = ypgService.getSurveyPointSituation(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }




    /**
     * 预评估二级页面  各省已提交房屋数量统计  //ypg_pro_house_num_count
     *
     * @return
     */
    @GetMapping("/getProHouseNumCount")
    public RestResponse getProHouseNumCount(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            if (PlatformObjectUtils.isEmpty(code)){
                code="0";
            }
            List<YpgProHouseNumCount> list = ypgService.getProHouseNumCount(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }



    /**
     * 预评估二级页面  房屋建筑物结构类型统计   //ypg_house_type_count
     *
     * @return
     */
    @GetMapping("/getHouseTypeCount")
    public RestResponse getHouseTypeCount(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            if (PlatformObjectUtils.isEmpty(code)){
                code="0";
            }
            List<YpgHouseTypeCount> list = ypgService.getHouseTypeCount(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    /**
     * 预评估二级页面  房屋建筑物结构类型统计   //ypg_build_monomer_count
     *
     * @return
     */
    @GetMapping("/getBuildMonomerCount")
    public RestResponse getBuildMonomerCount(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            if (PlatformObjectUtils.isEmpty(code)){
                code="0";
            }
            List<YpgBuildMonomerCount> list = ypgService.getBuildMonomerCount(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 预评估二级页面  4.2.51各省(直辖市）灾害风险点统计   //ypg_pro_damage_point_count
     *
     * @return
     */
    @GetMapping("/getDamagePointCount")
    public RestResponse getDamagePointCount(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            if (PlatformObjectUtils.isEmpty(code)){
                code="0";
            }
            List<YpgProDamagePointCount> list = ypgService.getDamagePointCount(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 预评估二级页面  灾害风险点类型统计（全国）   //ypg_damage_point_type_count
     *
     * @return
     */
    @GetMapping("/getDamagePointTypeCount")
    public RestResponse getDamagePointTypeCount(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            if (PlatformObjectUtils.isEmpty(code)){
                code="0";
            }
            List<YpgDamagePointTypeCount> list = ypgService.getDamagePointTypeCount(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }



    /**
     * 预评估二级页面  灾害风险点采集情况统计（全国）   //ypg_damage_point_situation_count
     *
     * @return
     */
    @GetMapping("/getDamagePointSituationCount")
    public RestResponse getDamagePointSituationCount(String code) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            if (PlatformObjectUtils.isEmpty(code)){
                code="0";
            }
            List<YpgDamagePointSituationCount> list = ypgService.getDamagePointSituationCount(code);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    /**
     * 预评估二级页面  ypg_pro_survey_point_count   各省（直辖市）抽样调查点数量统计 建筑物单体，灾害风险点 地图数据接口
     *
     * @return
     */
    @GetMapping("/getSurveyPointCountMap")
    public RestResponse getSurveyPointCountMap(String code,String flag) {
        //flag=0  表示抽样调查点   1表示建筑物单体  2表示灾害风险点
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            List<YpgProSurveyPointCountMapVO> list = ypgService.getSurveyPointCountMap(code,flag);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }



}
